function losMap() {
	var los_map = map.layers[5];
	var canvas = $("canvas");
	
	var SCREEN_WIDTH = 4096;
	var TILE_WIDTH = 64;
	var TILE_HEIGHT = 32;
	var SCREEN_HEIGHT = 2096;

	var los_blockers = []
	
	for ( var i = 0; i < los_map.objects.length; i++) {
		var obj = los_map.objects[i];
		var canvasLine = {
				  strokeStyle: "#000",
				  strokeWidth: 3};
		var objxo = obj.x;
		var objyo = obj.y;
		var objx = ((objxo - objyo)); 
        var objy = ((objxo + objyo)  / 2);
        
		for ( var l = 0; l < obj.polyline.length; l++) {
			var oy = (obj.polyline[l].y)/TILE_HEIGHT;
			var ox = (obj.polyline[l].x)/TILE_HEIGHT;
			var originX = SCREEN_WIDTH / 2 + objx;
			var originY = objy;
			
			var x = ((ox - oy) * TILE_WIDTH / 2) + originX; // 15,60
	        var y = ((ox + oy) * TILE_HEIGHT / 2) + originY;
			
	        if(l>0) {
	        	var x0 =canvasLine["x"+(l)]
	        	var y0=canvasLine["y"+(l)]
		        los_blockers.push( {"x1": x0, "y1": y0,"x2": x,"y2":y});
	        }
	        
			canvasLine["x"+(l+1)] = x;
			canvasLine["y"+(l+1)] = y;
		}
		$("canvas").drawLine(canvasLine);
	}
	
	
	function lineIntersection(line1,line2) {
		function inter(a1, a2, b1, b2) {
			var result;
			var ua_t = (b2.x - b1.x) * (a1.y - b1.y) - (b2.y - b1.y)
					* (a1.x - b1.x);
			var ub_t = (a2.x - a1.x) * (a1.y - b1.y) - (a2.y - a1.y)
					* (a1.x - b1.x);
			var u_b = (b2.y - b1.y) * (a2.x - a1.x) - (b2.x - b1.x)
					* (a2.y - a1.y);
			if (u_b != 0) {
				var ua = ua_t / u_b;
				var ub = ub_t / u_b;
				if (0 <= ua && ua <= 1 && 0 <= ub && ub <= 1) {
					result = {"x":a1.x + ua * (a2.x - a1.x), "y": a1.y + ua * (a2.y - a1.y)}
				} else {
					result = false;
				}
			} else {
				if (ua_t == 0 || ub_t == 0) {
					result = false;
				} else {
					result = false;
				}
			}
			return result;
		}
		
		var a1 = {"x":line1.x1, "y": line1.y1};
		var a2 = {"x":line1.x2, "y": line1.y2};
		var b1 = {"x":line2.x1, "y": line2.y1};
		var b2 = {"x":line2.x2, "y": line2.y2};
		
		return inter(a1,a2,b1,b2)

	}
	
	
	var resolution = 0.01;
	this.drawSight = function(x,y,angle,R) {
		var t = new Date();
		
		angle+=	(Math.PI/2)
		$("canvas").clearCanvas();
		var points = [{"x":x,"y":y}];
		
		for ( var a = angle; a < angle+(Math.PI/4); a+=resolution) {
			var line = {};
			line["x1"] = x;
			line["y1"] = y;
			line["x2"] = x+(Math.cos(a)*R);
			line["y2"] = y+(Math.sin(a)*R);
			for ( var i = 0; i < los_blockers.length; i++) {
				var interSect = lineIntersection(line,los_blockers[i]);
				if(interSect) {
					line["x2"] = interSect.x;
					line["y2"] = interSect.y;
					continue;
				}
			}
			
			points.push({"x":line["x2"],"y":line["y2"]})
		}
		canvas.draw(function(ctx) {
			ctx.fillStyle = '#0F0';
			ctx.beginPath();
			ctx.moveTo(points[0].x,points[0].y)
			for ( var i = 1; i < points.length; i++) {
				ctx.lineTo(points[i].x,points[i].y)
			}
			ctx.closePath();
			ctx.fill();
		})
		
		console.log(new Date() - t)
		
	}
	
};

